﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using smartphone.App_Code;

namespace smartphone.UserControls
{
    public partial class SearchBox : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string searchText = Request.QueryString["Search"];
                string allWords = Request.QueryString["AllWords"];
                if (allWords != null)
                {
                    allWordsCheckBox.Checked = (allWords.ToUpper() == "TRUE");
                }
                if (searchText != null)
                {
                    searchTextBox.Text = searchText;
                }
            }
        }

        protected void goButton_Click(object sender, EventArgs e)
        {
            ExecuteSearch();
        }

        private void ExecuteSearch()
        {
            string searchText = searchTextBox.Text;
            bool allWords = allWordsCheckBox.Checked;

            if (searchTextBox.Text.Trim() != "")
            {
                Response.Redirect(LinkClass.ToSearch(searchText, allWords, "1"));
            }
        }
    }
}